using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Betarium.PotonEditor
{
	public class ToolInfoPen : ToolInfo
	{
		public ToolInfoPen(EditViewForm form)
			: base(form)
		{
		}

		public override void OnMouseDown(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseDown(sender, e);
			Point cursorPos = m_Form.TransformClientToImage(e.Location);

			if (e.Button == MouseButtons.Left)
			{
                this.m_Form.AddUndo();
                Graphics graph = Graphics.FromImage(m_Form.Image);
				graph.FillRectangle(new SolidBrush(m_Form.PaintState.MainColor), new Rectangle(cursorPos, new Size(1, 1)));
				graph.Dispose();
				m_Form.SetModified(true);
			}
		}
		public override void OnMouseUp(object sender, MouseEventArgs e)
		{
			bool bMouseLeftDown = m_Form.SelectState.MouseLeftDown;
			Point mouseMoveBefore = m_Form.SelectState.MouseBeforePos;
			m_Form.SelectState.OnMouseUp(sender, e);
			Point cursorPos = m_Form.TransformClientToImage(e.Location);
			if (m_Form.SelectState.MouseLeftDown)
			{
                this.m_Form.AddUndo();
                Graphics graph = Graphics.FromImage(m_Form.Image);
				graph.DrawLine(new Pen(m_Form.PaintState.MainColor), mouseMoveBefore, cursorPos);
				graph.Dispose();
				m_Form.SetModified(true);
			}
		}
		public override void OnMouseMove(object sender, MouseEventArgs e)
		{
			m_Form.SelectState.OnMouseMove(sender, e);
			Point mouseMoveBefore = m_Form.SelectState.MouseBeforePos;
			Point cursorPos = m_Form.TransformClientToImage(e.Location);
			if (m_Form.SelectState.MouseLeftDown)
			{
                this.m_Form.AddUndo();
                Graphics graph = Graphics.FromImage(m_Form.Image);
				graph.DrawLine(new Pen(m_Form.PaintState.MainColor), mouseMoveBefore, cursorPos);
				graph.Dispose();
				m_Form.SetModified(true);
			}
		}
	}
}
